
// 初始化DataGrid对象
// $('#dataGrid').dataGrid({
//     searchForm: $("#searchForm"),
//     columnModel: [
//         {header:'机构名称', name:'officeName', index:'a.office_name', width:300, align:"left", frozen:true, formatter: function(val, obj, row, act){
//                 return '( '+row.viewCode+' ) '+'<a href="/js/a/sys/office/form?officeCode='+row.officeCode+'" class="btnList" data-title="编辑机构">'+(val||row.id)+'</a>';
//             }},
//         {header:'机构全称', name:'fullName', index:'a.full_name', width:200, align:"left"},
//         {header:'排序号', name:'treeSort', index:'a.tree_sort', width:80, align:"center"},
//         {header:'机构类型', name:'officeType', index:'a.office_type', width:100, align:"center", formatter: function(val, obj, row, act){
//                 return js.getDictLabel([{"cssStyle":"","cssClass":"","dictValue":"1","dictLabel":"省级公司"},{"cssStyle":"","cssClass":"","dictValue":"2","dictLabel":"市级公司"},{"cssStyle":"","cssClass":"","dictValue":"3","dictLabel":"部门"}], val, '未知', true);
//             }},
//         {header:'更新时间', name:'updateDate', index:'a.update_date', width:150, align:"center"},
//         {header:'备注信息', name:'remarks', index:'a.remarks', width:100, align:"left"},
//         {header:'状态', name:'status', index:'a.status', width:80, align:"center", formatter: function(val, obj, row, act){
//                 return js.getDictLabel([{"cssStyle":"","cssClass":"badge bg-green","dictValue":"0","dictLabel":"正常"},{"cssStyle":"color:#f00;","cssClass":"","dictValue":"1","dictLabel":"删除"},{"cssStyle":"color:#f00;","cssClass":"badge bg-red","dictValue":"2","dictLabel":"停用"},{"cssStyle":"color:#fa0;","cssClass":"","dictValue":"3","dictLabel":"冻结"},{"cssStyle":"","cssClass":"","dictValue":"4","dictLabel":"待审"},{"cssStyle":"","cssClass":"","dictValue":"5","dictLabel":"驳回"},{"cssStyle":"color:#aaa;","cssClass":"","dictValue":"9","dictLabel":"草稿"}], val, '未知', true);
//             }},
//         {header:'操作', name:'actions', width:150, formatter: function(val, obj, row, act){
//                 var actions = [];
//                 actions.push('<a href="/js/a/sys/office/form?officeCode='+row.officeCode+'" class="btnList" title="编辑机构"><i class="fa fa-pencil"></i></a>&nbsp;');
//                 if (row.status == Global.STATUS_NORMAL){
//                     actions.push('<a href="/js/a/sys/office/disable?officeCode='+row.officeCode+'" class="btnList" title="停用机构" data-confirm="确认要停用该机构吗？"><i class="glyphicon glyphicon-ban-circle"></i></a>&nbsp;');
//                 } else if (row.status == Global.STATUS_DISABLE){
//                     actions.push('<a href="/js/a/sys/office/enable?officeCode='+row.officeCode+'" class="btnList" title="启用机构" data-confirm="确认要启用该机构吗？"><i class="glyphicon glyphicon-ok-circle"></i></a>&nbsp;');
//                 }
//                 actions.push('<a href="/js/a/sys/office/delete?officeCode='+row.officeCode+'" class="btnList" title="删除机构" data-confirm="确认要删除该机构及所有子机构吗？" data-deltreenode="'+row.id+'"><i class="fa fa-trash-o"></i></a>&nbsp;');
//                 actions.push('<a href="/js/a/sys/office/form?parentCode='+row.id+'" class="btnList" title="新增下级机构"><i class="fa fa-plus-square"></i></a>&nbsp;');
//                 return actions.join('');
//             }}
//     ],
//     treeGrid: true,			// 启用树结构表格
//     defaultExpandLevel: 0,	// 默认展开的层次
//     expandNodeClearPostData: 'viewCode,officeName,fullName,officeType,', // 展开节点清理请求参数数据（一般设置查询条件的字段属性，否则在查询后，不能展开子节点数据）	// 加载成功后执行事件
//     ajaxSuccess: function(data){
//         if ($('#officeCode').val() != ''){
//             $('#officeCode').val('');
//             $('#btnExpandTreeNode').click();
//         }
//     }
// });
// $('#btnExport').click(function(){
//     js.ajaxSubmitForm($('#searchForm'), {
//         url:'/js/a/sys/office/exportData',
//         downloadFile:true
//     });
// });
// $('#btnImport').click(function(){
//     js.layer.open({
//         type: 1,
//         area: ['400px'],
//         title: '导入机构数据',
//         resize: false,
//         scrollbar: true,
//         content: js.template('importTpl'),
//         success: function(layero, index){
//             layero.find('input[type="checkbox"]').iCheck();
//         },
//         btn: ['<i class="fa fa-check"></i> 导入',
//             '<i class="fa fa-remove"></i> 关闭'],
//         btn1: function(index, layero){
//             var form = {
//                 inputForm: layero.find('#inputForm'),
//                 file: layero.find('#file').val()
//             };
//             if (form.file == '' || (!js.endWith(form.file, '.xls') && !js.endWith(form.file, '.xlsx'))){
//                 js.showMessage("文件不正确，请选择后缀为“xls”或“xlsx”的文件。", null, 'warning');
//                 return false;
//             }
//             js.ajaxSubmitForm(form.inputForm, function(data){
//                 js.showMessage(data.message);
//                 if(data.result == Global.TRUE){
//                     js.layer.closeAll();
//                 }
//                 page();
//             }, "json");
//             return true;
//         }
//     });
// });

$(function () {
    $('#table1').jqGrid({
        url: ctx + "/mge/adx/listTreeMenus?rad=" + new Date().getTime(),
        mtyep: 'post',
        postData: {},
        colModel: [
            {label: '菜单ID', name: 'id', width: 100, hidden: true, key: true},
            {label: '菜单名称', name: 'name', width: 85},
            {label: '上级菜单', name: 'pid', align: 'center', valign: 'middle', width: 100},
            {
                label: '图标', name: 'icon', align: 'center', valign: 'middle', width: 80, formatter: function (v, o, item) {
                return item.icon == null ? '' : '<i class="' + item.icon + ' fa-lg"></i>';
            }
            },
            {
                label: '类型', name: 'type', align: 'center', valign: 'middle', width: 100, formatter: function (v, o, item) {
                if (item.type === 0) {
                    return '<span class="label label-primary">目录</span>';
                }
                if (item.type === 1) {
                    return '<span class="label label-success">菜单</span>';
                }
                if (item.type === 2) {
                    return '<span class="label label-warning">按钮</span>';
                }
            }
            }, {
                label: '排序号', name: 'orderNum', align: 'center', valign: 'middle'
            }, {
                label: '菜单URL', name: 'url', align: 'center', valign: 'middle'
            }, {
                label: '授权标识', name: 'perms', align: 'center', valign: 'middle'
            }
        ],
        autowidth: true,//自动宽高
        height: "500",
        treeGrid: true,			// 启用树结构表格
        defaultExpandLevel: 0,	// 默认展开的层次
        treeGridModel: 'adjacency',
        treeReader: {
            parent_id_field: 'pid',
            level_field: 'level',
            leaf_field: "leaf",//是否叶子节点
            expanded_field: "expanded"//是否默认展开
            // level_field: "treeLevel",
            // parent_id_field: "parentCode",
            // userdata: "otherData",
            // leaf_field: "isTreeLeaf",
            // expanded_field: "isOpen",
            // icon_field: "_icon"
        },
        datatype: 'json',
        ExpandColumn: "name",
        expandNodeClearPostData: 'name', // 展开节点清理请求参数数据（一般设置查询条件的字段属性，否则在查询后，不能展开子节点数据）
                                         // 加载成功后执行事件
        loadComplete: function (data) {
            debugger
            if (data != null && data.code == 200) {
                return data.rows;
            }
            else {
                return [];
            }
        }
        , beforeRequest: function (data) {

        },
        gridComplete: function () {

        }
    });
});
